package LeetCode;

import Constructs.TreeNode;

//
// Created by ✎﹏ℳ๓独赏☆独醉 on 2024/6/23.
// 
public class 完全二叉树的节点个数 {
    public static void main(String[] args) {
//        System.out.println(countNodes(new TreeNode(1,new TreeNode(2,new TreeNode(4),new TreeNode(5)),new TreeNode(3,new TreeNode(6),null))));
//        System.out.println(countNodes(null));
//        System.out.println(countNodes(new TreeNode(1)));
        System.out.println(countNodes(new TreeNode(1,new TreeNode(2),null)));
    }
    static int count = 0;
    public static int countNodes(TreeNode root) {
        if(root == null){
            return count;
        }else {
            count++;
        }
        if(root.left != null){
            count = countNodes(root.left);
        }
        if(root.right != null){
            count = countNodes(root.right);
        }
        return count;
    }
}
